<?php
/**
 * Created by PhpStorm.
 * User: fengsen
 * Date: 16-7-15
 * Time: 上午11:21
 */
require_once ('clSqlOperation.php');
require_once ('clJson.php');
require_once ('clInReg.php');
class clSet extends clJson
{
    private $userName;
    private $userPwd;
    private $userNewP;
    private $backVal;
    function __construct($requestJson)
    {
        parent::__construct($requestJson);
        $this->userName = parent::fnGetJson()['user_name'];
        $this->userPwd = parent::fnGetJson()['user_passwd'];
        $this->userNewP = parent::fnGetJson()['user_new_passwd'];
        $this->backVal = null;
    }

    /**
     * @return bool|null|string
     *function:验证用户并提供修改密码服务
     *parament:
     */
    function fnEditPw(){
        //实现用户的修改密码功能
        $data = array(
            'user_name' => $this->userName,
            'user_passwd' => $this->userPwd,
            'user_phone' => null
        );
        $check = new clInReg(json_encode($data,JSON_UNESCAPED_UNICODE));
        $verify = $check->fnCheck();
        if($verify == true){
            $userInfo = array(
                'user_name' => $this->userName,
                'user_passwd' => $this->userNewP
            );
            $sqlQuery = new clSqlOperation($userInfo,"user_info","user_name = '$this->userName'",null);
            $result = $sqlQuery->fnUpdate();
            if($result != null)
                $this->backVal = true;
            else
                $this->backVal = false;
        }else
            $this->backVal = "账号和密码不匹配，请重新输入！";
        return $this->backVal;
    }
}